<?php


namespace Soen\Log\Handler;


use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;

class RotatingFileResetHandler extends RotatingFileHandler
{
    public $filenameOrigin;
    public function __construct(string $filename, int $maxFiles = 0, $level = Logger::DEBUG, bool $bubble = true, int $filePermission = null, bool $useLocking = false)
    {
        $this->filenameOrigin = $filename;
        parent::__construct($filename, $maxFiles, $level, $bubble, $filePermission, $useLocking);
    }
    
    /**
     * {@inheritDoc}
     */
    protected function getDefaultFormatter(): FormatterInterface
    {
        return new LineFormatter("[%datetime%] %channel%.%level_name%: [%file_line%] %message% %context%\n", 'Y-m-d H:i:s', true);
    }
//    protected function write(array $record): void
//    {
//        clearstatcache();
//        var_dump(is_file($this->url));
//        if (!is_file($this->url) && is_dir(dirname($this->url))) {
//            fclose($this->stream);
//            $this->close();
//            clearstatcache();
//            $dirFile = pathinfo($this->filenameOrigin)['dirname'] . '/' . pathinfo($this->url)['basename'];
//            fopen($dirFile, 'a+');
//        }
//        parent::write($record); // TODO: Change the autogenerated stub
//    }
}